package business;


import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.ConfigXmlParser;
import util.Utility;
import dao.ActivityOptionDAO;

public class InitProject extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public InitProject() {
		super();
	}

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.sendRedirect(Utility.JSP_Login);
	}



	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		//Initialize Configuration
		Utility.SERVER_REALPATH = getServletContext().getRealPath("/");
		ConfigXmlParser cxp = ConfigXmlParser.newInstance();
		Utility.DB_SERVERNAME = cxp.getServerName();
		Utility.DB_SERVERPORT = cxp.getServerPort();
		Utility.DB_DATABASENAME = cxp.getDatabaseName();
		Utility.DB_USERNAME = cxp.getUserName();
		Utility.DB_PASSWORD = cxp.getPassword();
		
		Utility.CONSTANT_APPROPRIATEAGE = cxp.getAppropriateAge();
		Utility.CONSTANT_APPROPRIATECLASS = cxp.getAppropriateClass();
		Utility.CONSTANT_ACTIVITYTYPE = cxp.getActivityType();
		Utility.CONSTANT_INDIVIDUALTEACHINGWAY = cxp.getIndividualTeachingWay();
		
		Utility.CONSTANT_DEGREE = cxp.getDegree();
		Utility.CONSTANT_ASSIGNMENT = cxp.getAssignment();
		Utility.CONSTANT_LIABILITY = cxp.getLiability();
		Utility.CONSTANT_LEFTEAR = cxp.getLeftear();
		Utility.CONSTANT_RIGHTEAR = cxp.getRightear();
		Utility.CONSTANT_ALLOCATION = cxp.getAllocation();
		Utility.CONSTANT_CLASSSORT = cxp.getClassSort();
		Utility.CONSTANT_CLASSATTRIBUTE = cxp.getClassAttribute();
		Utility.CONSTANT_SERVICETYPE = cxp.getServiceType();
		Utility.CONSTANT_FREQUENCY = cxp.getFrequency();
		Utility.CONSTANT_INDIVIDUALTIMING = cxp.getIndividualTiming();
		Utility.CONSTANT_ROLEID = cxp.getRoleID();
		Utility.CONSTANT_TEACHINGWAY = cxp.getTeachingWay();
		Utility.CONSTANT_DEVELOPMENTDOMAIN = cxp.getDevelopmentDomain();
		Utility.CONSTANT_COMPLETEENTERING = cxp.getCompleteEntering();
		
		
		if (cxp.getCollectivityTeachingWay() == null) {
			Utility.CONST_COLLECTIVITYTEACHINGWAYSINGLE = cxp.getCollectivityTeachingWaySingle();
		} else {
			Utility.CONSTANT_COLLECTIVITYTEACHINGWAY = cxp.getCollectivityTeachingWay();
		}
		Utility.JSP_IndividualTeachingPlan = cxp.getIndividualTeachingPlan();
		Utility.JSP_CollectivityTeachingPlan = cxp.getCollectivityTeachingPlan();
		Utility.JSP_AllTeachingPlan = cxp.getAllTeachingPlan();
		Utility.JSP_MyTeachingPlan = cxp.getMyTeachingPlan();
		Utility.JSP_UploadTP = cxp.getUploadTP();
		Utility.JSP_Upload = cxp.getUpload();
		Utility.JSP_AdvancedQuery = cxp.getAdvancedQuery();
		Utility.JSP_ITPEdit = cxp.getITPEdit();
		Utility.JSP_CTPEdit = cxp.getCTPEdit();
		Utility.JSP_TeacherAdd = cxp.getTeacherAdd();
		Utility.JSP_TeacherInfo = cxp.getTeacherInfo();
		Utility.JSP_TeacherEdit = cxp.getTeacherEdit();
		Utility.JSP_StudentAdd = cxp.getStudentAdd();
		Utility.JSP_StudentInfo = cxp.getStudentInfo();
		Utility.JSP_StudentEdit = cxp.getStudentEdit();
		Utility.JSP_CollectivityClassAdd = cxp.getCollectivityClassAdd();
		Utility.JSP_CollectivityClassInfo = cxp.getCollectivityClassInfo();
		Utility.JSP_CollectivityClassEdit = cxp.getCollectivityClassEdit();
		Utility.JSP_IndividualClassAdd = cxp.getIndividualClassAdd();
		Utility.JSP_IndividualClassInfo = cxp.getIndividualClassInfo();
		Utility.JSP_IndividualClassEdit = cxp.getIndividualClassEdit();
		Utility.JSP_Login = cxp.getLogin();
		Utility.JSP_LoginAdd = cxp.getLoginAdd();
		Utility.JSP_UserAdd = cxp.getUserAdd();
		Utility.JSP_UserInfo = cxp.getUserInfo();
		Utility.JSP_UserEdit = cxp.getUserEdit();
		Utility.JSP_PrintITP = cxp.getPrintITP();
		Utility.JSP_PrintTP = cxp.getPrintTP();
		Utility.JSP_SearchTeacherInfo = cxp.getSearchTeacherInfo();
		Utility.JSP_SearchCollectivityClassInfo = cxp.getSearchCollectivityClassInfo();
		Utility.JSP_SearchIndividualClassInfo = cxp.getSearchIndividualClassInfo();
		Utility.JSP_CollectivityTeachingPlanWeek = cxp.getCollectivityTeachingPlanWeek();
		Utility.JSP_CTeachingPlanWeekInfo = cxp.getCTeachingPlanWeekInfo();
		Utility.JSP_CTPWeekArrangeEdit = cxp.getCTPWeekArrangeEdit();
		Utility.JSP_CTPWeekNetwork = cxp.getCTPWeekNetwork();
		Utility.JSP_CollectivityTeachingPlanMonth = cxp.getCollectivityTeachingPlanMonth();
		Utility.JSP_CTeachingPlanMonthInfo = cxp.getCTeachingPlanMonthInfo();
		Utility.JSP_CTPMonthArrangeEdit = cxp.getCTPMonthArrangeEdit();
		Utility.JSP_CTPMonthNetwork = cxp.getCTPMonthNetwork();
		Utility.JSP_IndividualTeachingPlanWeek = cxp.getIndividualTeachingPlanWeek();
		Utility.JSP_ITeachingPlanWeekInfo = cxp.getITeachingPlanWeekInfo();
		Utility.JSP_ITPWeekArrangeEdit = cxp.getITPWeekArrangeEdit();
		Utility.JSP_ITPWeekNetwork = cxp.getITPWeekNetwork();
		Utility.JSP_ITPWNetworkMore = cxp.getITPWNetworkMore();
		Utility.JSP_CTPWNetworkMore = cxp.getCTPWNetworkMore();
		Utility.JSP_CTPMNetworkMore = cxp.getCTPMNetworkMore();
		Utility.JSP_PrintITPHomework = cxp.getPrintITPHomework();
		Utility.JSP_PrintCTPHomework = cxp.getPrintCTPHomework();
		Utility.JSP_PrintITPWeek = cxp.getPrintITPWeek();
		Utility.JSP_PrintCTPWeek = cxp.getPrintCTPWeek();
		Utility.JSP_PrintCTPMonth = cxp.getPrintCTPMonth();
		
		//Initialize ActivityOption from DB
		ActivityOptionDAO aoDAO = new ActivityOptionDAO();
		try {
			Utility.CONSTANT_ACTIVEOPTION = aoDAO.getAO();
		} catch (SQLException e) {
			
		}
	}

}
